// ============================== 导入依赖 ============================== //

import UTIL from '@admin/views/Monitor/Elec/UTIL'

const TIME = ['时间', 'time', '']

// ============================== 导出计算属性 ============================== //

export default {
  /**
   * 自定义计算属性 (可覆盖)
   */
  GETTER: ({ DICT, param, list }, getters, rootState) => {
    const { monitorPointType: pointType } = rootState.one
    const typeDict = pointType === 1 ? DICT.TYPE_TRANS : pointType === 2 ? DICT.TYPE_CIRCUIT : []
    const matched = typeDict.find(([id]) => param.type === id) || []
    const fieldDict = matched[2] || []

    const hourList = UTIL.transHourList(list, param.startTime)

    return {
      // 类型字典
      typeDict,

      // 类型标题
      typeTitle: rootState.DICT.TAB[1][1],

      // 类型名称
      typeName: matched[1],

      // 整点列表
      hourList,

      // 表格
      table: {
        rows: [TIME, ...fieldDict],
        list: UTIL.transFieldList(hourList, fieldDict),
      },

      // 图表
      chart: {
        xData: hourList.map((row) => row.date),
        dataList: fieldDict.map(([, field]) => hourList.map((item) => item[field] || 0)),
        dataNames: fieldDict.map(([name]) => name),
        dataUnits: fieldDict.map(([, , unit = '']) => unit),
      },
    }
  },
}
